package com.nulldev.util.web.YouTubeExtractor.demo;

import java.util.List;

import com.nulldev.util.JVM.Arguments;
import com.nulldev.util.JVM.JVM;
import com.nulldev.util.VariableAPI.ArrayUtils;
import com.nulldev.util.concurrency.threadIt.v4.emapi.ExecutorManager;
import com.nulldev.util.concurrency.threadIt.v4.emapi.uft.Executable;
import com.nulldev.util.io.FastIO.FastIO;
import com.nulldev.util.web.YouTubeExtractor.YouTubeExtractor;
import com.nulldev.util.web.YouTubeExtractor.YoutubeExtractionOptions;
import com.nulldev.util.web.YouTubeExtractor.extractors.IYouTubeExtractor;
import com.nulldev.util.web.YouTubeExtractor.video.ExtractedVideo;
import com.nulldev.util.web.YouTubeExtractor.video.YouTubeVideo;
import com.nulldev.util.web.legacyURI.LegacyURIUtils;

public class RewriteDemo {

	public static void main(String[] args) {
		Arguments.setup(args);
		LegacyURIUtils.disableSSLVerification();
		final IYouTubeExtractor ex = YouTubeExtractor.get("ytiapi.native-rolling");
		ex.enableInstanceDebugging(true);
		final Executable<ExtractedVideo> f = ex.generateTask("XadIrDysFIk", YoutubeExtractionOptions.DEBUG_PRINT_API_RESPONSE,
				YoutubeExtractionOptions.SEND_X_GOOG_API_KEY);
		ExecutorManager.get().asyncSubmit(f);
		JVM.println("result: " + f.waitTillCompletion());
		if (f.result() == null) {
			throw new NullPointerException("Failed to get a result!");
		}
		if (f.result().supportsLateExtraction()) {
			f.result().awaitCompletion();
			JVM.println("lateExtraction: COMPLETE");
		}
		if (f.result().hasCommentData()) {
			JVM.println("commentData: " + f.result().getCommentData());
		}
		final long s = System.currentTimeMillis();
		if (f.result().getMetadata() != null)
			JVM.println("enhanced description: " + f.result().getMetadata().getEnhancedDescription());
		final long e = System.currentTimeMillis();
		JVM.println("lat: " + (e - s) + " ms");
		if (f.result() != null) {
			final List<YouTubeVideo> result = f.waitTillCompletion().videos();
			ArrayUtils.printLln(result);
			JVM.println(f.result().getMetadata());
		}
		FastIO.get().flush();
		JVM.exit();
	}
}
